home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / nasm095s.zip / RDOFF / RDX.C < prev    next >
C/C++ Source or Header  |  1997-07-27  |  2KB  |  62 lines

  1. /* rdx.c    RDOFF Object File loader program
  2.  *
  3.  * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
  4.  * Julian Hall. All rights reserved. The software is
  5.  * redistributable under the licence given in the file "Licence"
  6.  * distributed in the NASM archive.
  7.  */
  8.  
  9. /* note: most of the actual work of this program is done by the modules
  10.    "rdfload.c", which loads and relocates the object file, and by "rdoff.c",
  11.    which contains general purpose routines to manipulate RDOFF object
  12.    files. You can use these files in your own program to load RDOFF objects
  13.    and execute the code in them in a similar way to what is shown here. */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #include "rdfload.h"
  19. #include "rdoff.h"
  20. #include "symtab.h"
  21.  
  22. typedef int (*main_fn) (int,char**);    /* Main function prototype */
  23.  
  24. int main(int argc, char **argv)
  25. {
  26.     rdfmodule     * m;
  27.     main_fn    code;
  28.     symtabEnt    * s;
  29.  
  30.     if (argc < 2)
  31.     {
  32.     puts("usage: rdf <rdoff-executable> [params]\n");
  33.     exit(255);
  34.     }
  35.  
  36.     m = rdfload(argv[1]);
  37.  
  38.     if (! m)
  39.     {
  40.     rdfperror("rdf",argv[1]);
  41.     exit(255);
  42.     }
  43.  
  44.     rdf_relocate(m);    /* in this instance, the default relocation
  45.                values will work fine, but they may need changing
  46.                in other cases... */
  47.  
  48.     s = symtabFind(m->symtab, "_main");
  49.     if (! s)
  50.     {
  51.     fprintf(stderr,"rdx: could not find symbol '_main' in '%s'\n",argv[1]);
  52.     exit(255);
  53.     }
  54.  
  55.     code = (main_fn) s->offset;
  56.  
  57.     argv++, argc--;    /* remove 'rdx' from command line */
  58.  
  59.     return code(argc,argv);    /* execute */
  60. }
  61.  
  62.